package com.rickie.web;

import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.cola.extension.BizScenario;
import com.rickie.api.ICargoBookingService;
import com.rickie.api.ICargoRoutingService;
import com.rickie.dto.command.CargoBookCmd;
import com.rickie.dto.data.CargoDTO;
import com.rickie.extension.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author rickie
 * @version 1.0.0
 * @ClassName CargoController.java
 * @Description TODO
 * @createTime 2021年06月14日 15:43:00
 */
@RestController
@RequestMapping("cargo")
@Slf4j
public class CargoController {
    @Resource
    private ICargoBookingService cargoBookingService;

    @Resource
    private ICargoRoutingService cargoRoutingService;

    /**
     * 货物预定
     */
    @PostMapping("cargobooking")
    public SingleResponse<String> bookCargo(@RequestBody CargoBookCmd cmd){
        log.info("****Cargo Booked **** "+cmd.getBookingAmount());
        // 设置业务扩展点
        cmd.setBizScenario(BizScenario.valueOf(Constants.BIZ_BOOKING, Constants.USE_CASE_BOOKING,cmd.getFlag()));
        return cargoBookingService.bookCargo(cmd);
    }

    /**
     * 根据预定id查询货物
     */
    @GetMapping("findCargo")
    public SingleResponse<CargoDTO> findByBookingId(@RequestParam("bookingId") String bookingId) {
        log.info("****Cargo findByBookingId **** "+ bookingId);
        return cargoBookingService.findByBookingId(bookingId);
    }

    /**
     * 根据预定id查询货物路线
     */
    @PostMapping("cargorouting")
    public SingleResponse<String> routeCargo(@RequestParam("bookingId") String bookingId){
        log.info("****Cargo routeCargo **** "+ bookingId);
        return cargoRoutingService.routeCargo(bookingId);
    }
}
